<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\DB;

class Scheduling extends Model
{
    //
	protected $table='scheduling';
	protected $fillable=['class_name','company_id','status','store_id','start_day','end_day','type'];
	protected $hidden=[];

	public function create_sch($data_sch){

		return $id=$this->create($data_sch)->id;
	}

//	获取所有排班
	public function lists($where){
		 $res=$this->where(function ($query) use($where){
			$query->where(['company_id'=>$where['company_id'],'store_id'=>$where['store_id']]);
			if($where['class_name'] !=null ){
				$query->where(['class_name'=>$where['class_name']]);
			}
			if($where['start_time'] !=null ){
				$query->where('created_at','>',$where['start_time']);
			}
			if($where['end_time'] !=null ){
				$query->where('created_at','<',$where['end_time']);
			}
			if($where['status'] !=null ){
				$query->where(['status'=>$where['status']]);
			}
		})->with('sch_status')->paginate(config('app.page'));
		return $res;

	}

	public function sch_desc(){
		return $this->hasMany('App\Model\Sch_desc','scheduling_id');
	}




	public function staffInfo(){
		return $this->belongsTo('App\Model\Staff','staff_id');
	}

	public function store(){
		return $this->belongsTo('App\Model\Store','store_id');
	}

	public function sch_status(){
		return $this->belongsTo('App\Model\Sch_status','status','sch_id');
	}

}
